package com.brsya.movie.presenter;

import com.brsya.base.base.BasePresenter;
import com.brsya.base.bean.BaseListBean;
import com.brsya.base.bean.InventoryBean;
import com.brsya.base.bean.InventoryDetailBean;
import com.brsya.base.net.MyObserver;
import com.brsya.base.net.RxScheduler;
import com.brsya.movie.contract.InventoryDetailContract;
import com.brsya.movie.model.InventoryDetailModel;

import java.util.Map;

import io.reactivex.rxjava3.annotations.NonNull;

/**
 * Created by Brsya
 * CreateDate: 2022/7/7  10:37
 * Description:
 * 片单详情逻辑层
 */
public class InventoryDetailPresenter extends BasePresenter<InventoryDetailContract.View> implements InventoryDetailContract.Presenter {
    private InventoryDetailContract.Model model;

    public InventoryDetailPresenter() {
        model = new InventoryDetailModel();
    }

    @Override
    public void getInventoryDetail(int titleId) {
        mView.showLoading();

        Map<String, Object> par = getPublicPar();
        par.put("hvId", titleId);

        model.getInventoryDetail(par)
                .compose(RxScheduler.Obs_io_main())
                .to(mView.bindAutoDispose())
                .subscribe(new MyObserver<BaseListBean<InventoryDetailBean>>(mView) {
                    @Override
                    public void success(@NonNull BaseListBean<InventoryDetailBean> baseBean) {
                        baseBean.handleData(InventoryDetailBean.class);
                        if (baseBean.getData() == null || baseBean.getData().size() == 0) {
                            mView.noData();
                            return;
                        }
                        mView.showInventoryList(baseBean.getData());
                    }
                });

    }
}
